<?php

declare(strict_types=1);

namespace app\xapply;

use app\xapply\middleware\Auth;
use think\facade\Db;

class Xapply 
{
    protected $middleware = [Auth::class];

    protected $user = null;
    public $data = [];

    public function __construct()
    {
        $this->getValue();
    }

    public function getUserinfo(){
        if (empty($this->user)){
            $this->user = Db::name('Admin')->where(['id' => XAPPLY_UID])->find();
        }
        return $this->user;
    }

    protected function getValue(){
        $content = file_get_contents('php://input');
        if ($content){
            $arr = json_decode($content, true);
            $new = [];
            if ($arr){
                foreach ($arr as $key => $value){
                    if (is_string($value)){
                        $value = htmlspecialchars(trim($value));
                    }
                    $new[$key] = $value;
                }
            }
            $this->data = $new;
        }
    }
}
